<template>
  <div class="">
    <div class="filter-container">
      <el-input v-model="listQuery.name" clearable class="filter-item" style="width: 200px;" placeholder="搜索用户昵称"/>
      <el-button v-permission="['user:list']" class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">查找</el-button>
    </div>

    <el-table v-loading="listLoading" :data="list" size="small" element-loading-text="正在查询中..." border fit highlight-current-row>
      <el-table-column align="center" label="ID" width="100" prop="id" />
      <el-table-column align="center" label="昵称" width="120" prop="userName" />
      <el-table-column align="center" label="操作" prop="title" width="150"/>
      <el-table-column align="center" label="IP" prop="ip" width="150"/>
      <el-table-column align="center" label="结果" prop="success" width="100">
        <template slot-scope="scope">
          <el-tooltip v-if="!scope.row.success" :content="scope.row.content" class="item" effect="dark" placement="top">
            <el-link type="danger">失败</el-link>
          </el-tooltip>
          <el-link v-else :underline="false" type="success">成功</el-link>
        </template>
      </el-table-column>
      <el-table-column align="center" width="200" label="操作时间" prop="time"/>
      <el-table-column align="left" label="URL" prop="url"/>
    </el-table>
    <pagination v-permission="['user:list']" v-show="total>0" :total="total" :page.sync="listQuery.pageNo" :limit.sync="listQuery.pageSize" @pagination="getList"/>
  </div>
</template>

<script>
import { LogsService } from '@/api/SystemService'
import Pagination from '@/components/Pagination'

export default {
  name: 'UserLog',
  components: { Pagination },
  data() {
    return {
      list: null, total: 0, listLoading: true,
      listQuery: { pageNo: 1, pageSize: 20, name: undefined }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.listLoading = true
      LogsService.listUserLog(this.listQuery).then(response => {
        this.list = response.data
        this.total = response.totalCount
        this.listLoading = false
      })
    },
    handleFilter() {
      this.listQuery.pageNo = 1
      this.getList()
    }
  }
}
</script>

<style>
</style>
